package com.yxx.business.service.impl;

import java.util.List;

import com.yxx.common.utils.DateUtils;
import com.yxx.common.core.domain.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import com.yxx.common.core.service.impl.ServiceImplPlus;
import com.yxx.business.mapper.TbMaterialTransportMapper;
import com.yxx.business.entity.TbMaterialTransportDo;
import com.yxx.business.entity.TbMaterialTransportVo;
import com.yxx.business.entity.TbMaterialTransportQueryDto;
import com.yxx.business.entity.TbMaterialTransportEditDto;
import com.yxx.business.service.ITbMaterialTransportService;

/**
 * 材料运输信息Service业务层处理
 *
 * @author yxx
 * @date 2025-08-16
 */
@Slf4j
@Service
@RequiredArgsConstructor(onConstructor_ = {@Lazy, @Autowired})
public class TbMaterialTransportServiceImpl extends ServiceImplPlus<TbMaterialTransportMapper, TbMaterialTransportDo> implements ITbMaterialTransportService {

    private final TbMaterialTransportMapper tbMaterialTransportMapper;

    /**
     * 查询材料运输信息分页结果
     *
     * @param tbMaterialTransportQueryDto 材料运输信息查询实体
     * @return 材料运输信息分页
     */
    @Override
    public PageResult<TbMaterialTransportVo> selectTbMaterialTransportVoPage(TbMaterialTransportQueryDto tbMaterialTransportQueryDto) {
        startPage();
        PageResult<TbMaterialTransportVo> page
                = super.getMyBatisPageResult(selectTbMaterialTransportDoList(tbMaterialTransportQueryDto), TbMaterialTransportVo.class);
        clearPage();
        return page;
    }

    /**
     * 查询材料运输信息Vo列表
     *
     * @param tbMaterialTransportQueryDto 材料运输信息查询实体
     * @return 材料运输信息集合
     */
    @Override
    public List<TbMaterialTransportVo> selectTbMaterialTransportVoList(TbMaterialTransportQueryDto tbMaterialTransportQueryDto) {
        return super.convertVoList(tbMaterialTransportMapper.selectTbMaterialTransportList(tbMaterialTransportQueryDto), TbMaterialTransportVo.class);
    }

    /**
     * 查询材料运输信息Do列表
     *
     * @param tbMaterialTransportQueryDto 材料运输信息查询实体
     * @return 材料运输信息集合
     */
    @Override
    public List<TbMaterialTransportDo> selectTbMaterialTransportDoList(TbMaterialTransportQueryDto tbMaterialTransportQueryDto) {
        return tbMaterialTransportMapper.selectTbMaterialTransportList(tbMaterialTransportQueryDto);
    }

    /**
     * 查询单个材料运输信息
     *
     * @param materialId 材料运输信息主键
     * @return 材料运输信息单个
     */
    @Override
    public TbMaterialTransportVo selectTbMaterialTransportVoByMaterialId(Long materialId) {
        return super.convertBean(tbMaterialTransportMapper.selectTbMaterialTransportByMaterialId(materialId), TbMaterialTransportVo.class);
    }

    /**
     * 新增材料运输信息
     *
     * @param tbMaterialTransportQueryDto 材料运输信息编辑实体
     * @return 结果
     */
    @Override
    public int insertTbMaterialTransport(TbMaterialTransportEditDto tbMaterialTransportQueryDto) {
        tbMaterialTransportQueryDto.setCreateById(getUserIdOrNotLogged());
        tbMaterialTransportQueryDto.setCreateBy(getUserNameOrNotLogged());
        tbMaterialTransportQueryDto.setCreateTime(DateUtils.getNowDate());
        return tbMaterialTransportMapper.insertTbMaterialTransport(super.convertT(tbMaterialTransportQueryDto));
    }

    /**
     * 修改材料运输信息
     *
     * @param materialId 材料运输信息主键
     * @param tbMaterialTransportQueryDto 材料运输信息编辑实体
     * @return 结果
     */
    @Override
    public int updateTbMaterialTransport(Long materialId, TbMaterialTransportEditDto tbMaterialTransportQueryDto) {
        tbMaterialTransportQueryDto.setUpdateBy(getUserNameOrNotLogged());
        tbMaterialTransportQueryDto.setUpdateTime(DateUtils.getNowDate());
        return tbMaterialTransportMapper.updateTbMaterialTransport(super.convertT(tbMaterialTransportQueryDto).setMaterialId(materialId));
    }

    /**
     * 批量删除材料运输信息
     *
     * @param materialIds 需要删除的材料运输信息主键集合
     * @return 结果
     */
    @Override
    public int deleteTbMaterialTransportByMaterialIds(List<Long> materialIds) {
        return tbMaterialTransportMapper.deleteTbMaterialTransportByMaterialIds(materialIds);
    }

    /**
     * 删除单个材料运输信息信息
     *
     * @param materialId 材料运输信息主键
     * @return 结果
     */
    @Override
    public int deleteTbMaterialTransportByMaterialId(Long materialId) {
        return tbMaterialTransportMapper.deleteTbMaterialTransportByMaterialId(materialId);
    }
}
